//
//  ReadDetailController.m
//  liang ping
//
//  Created by lanou on 16/3/12.
//  Copyright © 2016年 孙金龙. All rights reserved.
//

#import "ReadDetailController.h"
#import "RequestManager.h"
#import "NSString+Html.h"


//#import "UMSocial.h"
typedef  NS_ENUM(NSInteger,ButtonType)
{
    AButton,
    CommentButton,
    CollectButton,
    MoreButton
};
//@interface ReadDetailController ()<UMSocialUIDelegate>

//@property(nonatomic,strong)UIButton *button;
//@property(nonatomic,assign)NSInteger buttonType;
//@end

@implementation ReadDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 20, KWidth, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 20, 1, 50)];
    label1.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:label1];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 71, KWidth, 1)];
    label2.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:label2];
    
    UILabel *xxx = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 100, 40)];
    xxx.text = _Title;
    xxx.textColor = [UIColor lightGrayColor];
    [view addSubview:xxx];
    
    [self CreatButton:AButton frame:CGRectMake(KWidth-200, 32, 30, 30)];
    [self CreatButton:CommentButton frame:CGRectMake(KWidth-150, 32, 30, 30)];
    [self CreatButton:CollectButton frame:CGRectMake(KWidth-70, 32, 30, 30)];
    [self CreatButton:MoreButton frame:CGRectMake(KWidth-50, 32, 30, 30)];
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button.frame = CGRectMake(5, 5, 40, 40);
    [self.button setImage:[UIImage imageNamed:@"u9_start.png" ]forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_button];
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 72, KWidth, KHeight-72)];
   
    
    NSDictionary *dic = [NSDictionary dictionaryWithObject:_contentId forKey:@"contentid"];
    [RequestManager requestWithUrl:@"http://api2.pianke.me/article/info" requestType:RequestTypePost parDic:dic finish:^(NSData *data) {
        NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        _htmlString = Dic[@"data"][@"html"];
        _htmlString = [NSString importStyleWithHtmlString:_htmlString];
        [webView loadHTMLString:_htmlString baseURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];
    } error:^(NSError *error) {
        
    }];
    [self.view addSubview:webView];
}


// 创建Button的方法
- (void)CreatButton:(ButtonType)buttonType frame:(CGRect)frame
{
    switch (buttonType)
    {
        case AButton:
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = frame;
            button.tag = 100+AButton;
            [button setTitle:@"A" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonTypeAction:) forControlEvents:UIControlEventTouchUpInside];
           // [self.view addSubview:button];
        }
            break;
        case CommentButton:
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = frame;
            button.tag = 100+CommentButton;
            [button setTitle:@"评论" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonTypeAction:) forControlEvents:UIControlEventTouchUpInside];
           // [self.view addSubview:button];
        }
            break;
        case CollectButton:
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = frame;
            button.tag = 100+CollectButton;
            [button setTitle:@"分享" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonTypeAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:button];
        }
            break;
        case MoreButton:
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = frame;
            button.tag = 100+MoreButton;
            [button setTitle:@"更多" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonTypeAction:) forControlEvents:UIControlEventTouchUpInside];
           // [self.view addSubview:button];
        }
            break;
        default:
            break;
    }
}

- (void)buttonTypeAction:(UIButton *)button
{
    [self ActionType:button.tag-100];
}

- (void)ActionType:(ButtonType)type
{
    switch (type)
    {
        case AButton:
        {
            NSLog(@"A");
        }
            break;
        case CommentButton:
        {
            NSLog(@"==============%d",[[NSUserDefaults standardUserDefaults] boolForKey:@"isLand"]);
            if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isLand"])
            {
               
            }
            else
            {
                
            }
        }
            break;
        case CollectButton:
        {
            NSLog(@"C");
            // 友盟第三方分享
//            [UMSocialSnsService presentSnsController:self appKey:@"56eb670ee0f55a8d91000d8a" shareText:@"分享" shareImage:nil shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToRenren,UMShareToTencent,nil] delegate:self];
        }
            break;
        case MoreButton:
        {
            NSLog(@"D");
        }
            break;
        default:
            break;
    }

}

// 返回button
- (void)buttonAction:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
